/**
 * 2015-12-21
 * TeacherServiceImpl.java
 * author:sherlochao
 */
package com.sherlochao.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.sherlochao.beans.TeacherBean;
import com.sherlochao.dao.TeacherDao;
import com.sherlochao.model.Course;
import com.sherlochao.model.Teacher;
import com.sherlochao.service.TeacherService;

/**
 * @author yinchao
 * 
 */
@Transactional
@Service("teacherService")
public class TeacherServiceImpl implements TeacherService {
	@Resource
	private TeacherDao teacherDao;

	@Override
	public Teacher get(String teacherId) {
		return teacherDao.get(teacherId);
	}

	@Override
	public List<Course> listCourseByTeacherId(String teacherId) {
		// TODO Auto-generated method stub
		return teacherDao.listCourseByTeacherId(teacherId);
	}

	@Override
	public List<Integer> listStudentByTeacherId(String teacherId) {
		// TODO Auto-generated method stub
		return teacherDao.listStudentByTeacherId(teacherId);
	}
	
	@Resource
	private TeacherService teacherService;
	
	@Override
	public String test(String teacherId){
		TeacherBean teacherBean = new TeacherBean();
		Teacher teacher = teacherService.get(teacherId);
		teacherBean.setTeacherId(teacher.getTeacherId());
		teacherBean.setTeacherName(teacher.getTeacherName());
		teacherBean.setTeacherBirthday(teacher.getTeacherBirthdate());
		List<Course> courses = teacherService.listCourseByTeacherId(teacherId);
		teacherBean.setCourses(courses);
		List<Integer> integers = teacherService.listStudentByTeacherId(teacherId);
		teacherBean.setStudents(integers);
		String json = JSON.toJSONString(teacherBean);
		return json;
	}

}
